package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

     //查询菜品分类列表
    @GetMapping("/list")
    public R categoryList(Integer type){
        return categoryService.categoryList(type);
    }
    //修改分类
    @PutMapping
    public R updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }
    //删除分类
    @DeleteMapping
    public R deleteCategory(Long id){
        return categoryService.deleteCategory(id);
    }
    //分类分页查询
    @GetMapping("/page")
    public R categoryPage(Integer page,Integer pageSize){
        return categoryService.categoryPage(page,pageSize);
    }

    //新增分类
    @PostMapping
    public R saveCategory(@RequestBody Category category, HttpSession session){
        return categoryService.addCategory(category,session);
    }
}

